package offer;

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;

import recruiter.Recruiter;
import student.Student;

import company.Company;
import compsup.CompanySup;
import descriptor.OfferDescriptor;

/**
 * OfferBean
 * 
 * 
 * The OfferBean class implements all the methods that a remote client expect to find
 * when it calls the interface (Offer).
 * 
 * Note :  -We use @SuppressWarnings("unchecked") to avoid the useless warnings
 */
@SuppressWarnings("unchecked")
public abstract class OfferBean implements EntityBean {

	static int PRIVATE = 0;
	static int PUBLIC = 1;
	
	public abstract int getId();
	public abstract void setId(int id);
	
	
	public abstract String getName();
	public abstract void setName(String name);
	
	public abstract int getType();
	public abstract void setType(int type);
	
	public abstract String getDescription();
	public abstract void setDescription(String description);
	
	public abstract Company getCompany();
	public abstract void setCompany(Company company);
	
	public abstract Recruiter getRecruiter();
	public abstract void setRecruiter(Recruiter recruiter);
	
	public abstract String getDateOfStart();
	public abstract void setDateOfStart(String dateOfStart);
	 
	public abstract String getDateOfEnd();
	public abstract void setDateOfEnd(String dateOfEnd);
	
	public abstract int getStatus();
	public abstract void setStatus(int status);
	
	public abstract Student getStudent();
	public abstract void setStudent(Student student);
	public abstract CompanySup getCompanySup();
	public abstract void setCompanySup(CompanySup companySup);

	
	public abstract String getDateOfInterview();
	public abstract void setDateOfInterview(String dateOfInterview);
	public abstract String getHourOfInterview();
	public abstract void setHourOfInterview(String hourOfInterview);
	public abstract String getMinuteOfInterview();
	public abstract void setMinuteOfInterview(String minuteOfInterview);
	public abstract String getAddressOfInterview();
	public abstract void setAddressOfInterview(String AddressOfInterview);
	
	public OfferDescriptor getDescriptor(){
		int studentId;
		String studentName ="";
		int companySupID = -1;
		int recruiterID = -1;
		String companySupName = "";
		String recruiterName ="";
		if(getStudent() == null){
			studentId = -1;
		}else{
			studentId = getStudent().getId();
			studentName = getStudent().getName() + " " + getStudent().getFirstName();
		}
		if(getCompanySup() != null)
		{
			companySupID = getCompanySup().getId();
			companySupName = getCompanySup().getSurname() +" "+getCompanySup().getFirstname();
		}
		if(getRecruiter() != null)
		{
			recruiterID = getRecruiter().getId();
			recruiterName = getRecruiter().getSurname()+" "+getRecruiter().getFirstname();
		}
		return new OfferDescriptor(getId(),getName(),getType(),getDateOfStart(),getDateOfEnd(),getDateOfInterview(),getHourOfInterview(),getMinuteOfInterview(),getAddressOfInterview(),getCompany().getId(),recruiterID,getCompany().getName(),recruiterName,studentId,studentName,getDescription(),getStatus(),companySupID,companySupName);
    }
	
	public void ejbActivate() throws EJBException, RemoteException {
		
	}

	public void ejbLoad() throws EJBException, RemoteException {
		
	}

	public void ejbPassivate() throws EJBException, RemoteException {
		
	}

	public void ejbRemove() throws RemoveException, EJBException, RemoteException {
		
	}

	public void ejbStore() throws EJBException, RemoteException {
		
	}

	public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException {
		
	}

	public void unsetEntityContext() throws EJBException, RemoteException {
		
	}
	public String ejbCreate(String name,String description, int type,String dateOfStart, String dateOfEnd, Company company,Recruiter recruiter,Student student,CompanySup companySup) throws CreateException{
		setName(name);
		setDescription(description);
		setType(type);
		setDateOfEnd(dateOfEnd);
		setDateOfStart(dateOfStart);
		setStatus(Offer.PUBLISH);
		return null;
		
	}
	public void ejbPostCreate(String name,String description, int type, String dateOfStart, String dateOfEnd, Company company,Recruiter recruiter,Student student,CompanySup companySup) throws CreateException{
		setCompany(company);
		setRecruiter(recruiter);
		setStudent(student);
		setCompanySup(companySup);
		
	}

}
